function $(ElementID) {
	return document.getElementById(ElementID);
}

window.onload = init;

function init() {
	$("username").onfocus = clear;
	$("password").onfocus = clear;
	$("captcha").onfocus = clear;
}

function validForm() {
	var loginName = $("username").value;
	var pwd = $("password").value;
	var captcha = $("captcha").value;
	var prompt = $("prompt");
	if(loginName == ""){
		if(pwd == ""){
			if(captcha == ""){
				prompt.innerHTML = "请输入账号、密码和验证码";
				prompt.style.display = "block";
				return false;
			}
			prompt.innerHTML = "请输入账号和密码";
			prompt.style.display = "block";
			return false;
		}
		if(captcha == ""){
			prompt.innerHTML = "请输入账号和验证码";
			prompt.style.display = "block";
			return false;
		}
		prompt.innerHTML = "请输入账号";
		prompt.style.display = "block";
		return false;
	} else if(pwd == ""){
		if(captcha == ""){
			prompt.innerHTML = "请输入密码和验证码";
			prompt.style.display = "block";
			return false;
		}
		prompt.innerHTML = "请输入密码";
		prompt.style.display = "block";
		return false;
	} else if(captcha == ""){
		prompt.innerHTML = "请输入验证码";
		prompt.style.display = "block";
		return false;
	} else if(checkLoginName() == false){
		prompt.innerHTML = "账号请输入6-10位的英文字母和数字";
		prompt.style.display = "block";
		return false;
	} else if(checkPwd() == false){
		prompt.innerHTML = "密码请输入6-10位的英文字母和数字";
		prompt.style.display = "block";
		return false;
	} else if(checkCaptcha() == false){
		prompt.innerHTML = "验证码请输入4位的英文字母";
		prompt.style.display = "block";
		return false;
	} else if(checkDtef() == false){
		prompt.innerHTML = "验证码输入错误,请重新输入";
		prompt.style.display = "block";
		return false;
	} else{
		return true;
	}
}

// 验证登录账号
function checkLoginName() {
	// var loginName = $("username").value;
	// var regLoginName = /^[a-zA-Z0-9]{6,10}$/;
	// if (regLoginName.test(loginName) == false) {
	// 	return false;
	// }
	return true;
}

// 验证登录密码
function checkPwd(){
	var pwd = $("password").value;
	var regPwd = /^[a-zA-Z0-9]{6,10}$/;
	if(regPwd.test(pwd) == false) {
		return false;
	}
	return true;
}

// 验证验证码格式是否正确
function checkCaptcha(){
	var captcha = $("captcha").value;
	var regCaptcha = /^[a-zA-Z]{4}$/;
	if(regCaptcha.test(captcha) == false) {
		return false;
	}
	return true;
}

// 验证验证码内容是否正确
function checkDtef(){
	var captcha = $("captcha").value;
	var dtef = /^[Dd]{1}[Tt]{1}[Ee]{1}[Ff]{1}$/;
	if(dtef.test(captcha) == false){
		return false;
	}
	return true;
}

// 清除提示信息
function clear(){
	$("prompt").style.display = "none";
}